<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // fetch(url, {配置项}).then(res => res.json()).then(res => {})
        // 如果用fetch发送post请求

        const api_login = 'http://ajax-api.itheima.net/login'
        // 要发送给后端的参数
        const params = {
            username: "admin",
            password: "123456"
        }

        fetch(api_login,{
            method: 'POST',
            headers:{
                'Content-Type':'application/json'
            },
            body:JSON.stringify(params)
            // 第一个then这种写法，是省略了return的
        }).then(res => res.json()).then(res => {
            console.log(res)
        })
        
    </script>
</body>
</html>